﻿using System.Windows;
using Microsoft.Phone.Controls;

namespace OneBusAway
{
    public partial class MainPage : PhoneApplicationPage
    {
        private ViewModel model = new ViewModel();

        public MainPage()
        {
            InitializeComponent();

            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;

            this.DataContext = model;

            this.model.PropertyChanged += (o, e) =>
                {
                    if (e.PropertyName == "SelectedStop")
                    {
                        this.ShowTab(this.StopTab);
                    }
                };
        }

        private void ShowLocalTab(object sender, RoutedEventArgs e)
        {
            this.ShowTab(this.LocalTab);

            var model = this.DataContext as ViewModel;
            if (model != null)
            {
                model.Geo.Start();
            }
        }

        private void ShowTab(FrameworkElement tab)
        {
            this.StopTab.Visibility = System.Windows.Visibility.Collapsed;
            this.LocalTab.Visibility = System.Windows.Visibility.Collapsed;

            tab.Visibility = System.Windows.Visibility.Visible;
        }
    }
}